
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Proxy extends UnicastRemoteObject {

	private static final String URI = "rmi://localhost/servidor";
	
	protected Proxy() throws RemoteException {}

	public static void main(String[] args) {
		
		try{ //Proxy atuando como Servidor
			Proxy proxy = new Proxy();
			LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
	        Naming.bind(URI, proxy);
	        System.out.println("Server proxy started and up!");
	        
	        try { //Proxy atuando como Cliente			
				IServidor servidor = (IServidor) Naming.lookup(URI);			
	        } 
	        catch (NotBoundException ex) {
	            Logger.getLogger(Proxy.class.getName()).log(Level.SEVERE, null, ex);
	        } 
	        
		} 
	    catch (AlreadyBoundException ex) {
	        Logger.getLogger(Proxy.class.getName()).log(Level.SEVERE, null, ex);
	    } 
	    catch (MalformedURLException ex) {
	        Logger.getLogger(Proxy.class.getName()).log(Level.SEVERE, null, ex);
	    } 
	    catch (RemoteException ex) {
	        Logger.getLogger(Proxy.class.getName()).log(Level.SEVERE, null, ex);
	    }	  	    
	    
	}

}
